<?php
class OrderAction extends CommonAction{

	public function index(){

		//自定义
		$Order=M('Order');

		$condForm['order_no'] = $_POST['order_no'];
		$condForm['product_no'] = $_POST["product_no"];
		$condForm['product_name'] = $_POST["product_name"];
		$condForm['first_name'] = $_POST["first_name"];
		$condForm['last_name'] = $_POST["last_name"];
		$condForm['express_no'] = $_POST["express_no"];

		if(!empty($condForm['order_no'])){
			$condition['order_no'] = array('like',makeSqlLikeValue($condForm['order_no']));
		}

		if(!empty($condForm['product_no'])){
			$condition['product_no'] = array('like',makeSqlLikeValue($condForm['product_no']));
		}

		if(!empty($condForm['product_name'])){
			$condition['product_name'] = array('like',makeSqlLikeValue($condForm['product_name']));
		}

		if(!empty($condForm['first_name'])){
			$condition['first_name'] = array('like',makeSqlLikeValue($condForm['first_name']));
		}

		if(!empty($condForm['last_name'])){
			$condition['last_name'] = array('like',makeSqlLikeValue($condForm['last_name']));
		}

		if(!empty($condForm['express_no'])){
			$condition['express_no'] = array('like',makeSqlLikeValue($condForm['express_no']));
		}

		import("@.ORG.Page"); //导入分页类
		$count = $Order->count();    //计算总数
		$p = new Page ( $count, 5 );
		if(isset($condition)){
			$list=$Order->where($condition)->limit($p->firstRow.','.$p->listRows)->order('id desc')->findAll();
		}else{
			$list=$Order->limit($p->firstRow.','.$p->listRows)->order('id desc')->findAll();
		}
		$p->setConfig('header','篇记录');
		$p->setConfig('prev',"<");
		$p->setConfig('next','>');
		$p->setConfig('first','<<');
		$p->setConfig('last','>>');
		$page = $p->show ();
		$this->assign("condForm",$condForm);
		$this->assign( "page", $page );
		$this->assign ( "list", $list );
		$this->display();
	}








	//====================
	
	// 编辑数据
	public function edit() {
		if(!empty($_GET['id'])) {
			$Order	=	D("Order");
			$vo = $Order->relation(true)->find($_GET['id']);
			if($vo) {
				$express_corp = M("Express");
				$this->assign("expresses", $express_corp->findAll());
				$this->assign('vo',$vo);
				$this->display();
			}else{
				exit('编辑项不存在！');
			}
		}else{
			exit('编辑项不存在！');
		}
	}

	// 更新数据
	public function update() {

		$Order=	D("Order");
		if($vo = $Order->create()) {
			$list=$Order->save();
			if($list!==false){
				$this->assign("vo",$Order);
				$this->success('数据更新成功！');
			}else{
				$this->error("没有更新任何数据!");
			}
		}else{
			$this->error($Order->getError());
		}
	}


}